package com.caigou.modules.article.adpter

import android.graphics.Color
import android.text.TextUtils
import android.widget.TextView
import com.caigou.comm.base.utils.ImageLoader
import com.caigou.modules.article.R
import com.caigou.modules.article.bean.ArticleItemBean
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder


/**
 * @author #Suyghur.
 * Created on 2021/09/23
 */
class ArticleItemAdapter(dataset: MutableList<ArticleItemBean>) : BaseQuickAdapter<ArticleItemBean, BaseViewHolder>(R.layout.item_article_list, dataset),
    LoadMoreModule {

    override fun convert(holder: BaseViewHolder, item: ArticleItemBean) {
        ImageLoader.load(context, item.cover, holder.getView(R.id.item_article_iv_cover))
        holder.setText(R.id.item_article_tv_cover_num, "共${item.imgs.size}张")

        if (TextUtils.isEmpty(item.userInfo.headImg)) {
            holder.setImageResource(R.id.item_article_iv_avatar, R.drawable.img_comm_avatar)
        } else {
            ImageLoader.loadCircle(context, item.userInfo.headImg, holder.getView(R.id.item_article_iv_avatar))
        }

        holder.setText(R.id.item_article_tv_nickname, item.userInfo.nickName)
        holder.setText(R.id.item_article_tv_title, item.title)
        holder.setText(R.id.item_article_tv_desc, item.content)
        holder.setText(R.id.item_article_tv_point, item.nicePoint.toString())
        if (item.like) {
            holder.setImageResource(R.id.item_article_iv_like, R.drawable.img_article_like)
            holder.getView<TextView>(R.id.item_article_tv_point).setTextColor(Color.parseColor("#FE6880"))
        } else {
            holder.setImageResource(R.id.item_article_iv_like, R.drawable.img_article_unlike)
            holder.getView<TextView>(R.id.item_article_tv_point).setTextColor(Color.parseColor("#505050"))
        }
    }
}